package com.wanxi.dangdang.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @Author: 寇文宝
 * @Description:  订单编号生成类
 * @Date: Created in 2021/8/31
 * @Version: 1.0
 */

public class GenerateOrderNoUtil {
    private static String date;

    public static synchronized String getOrderNo(){
        String str = new SimpleDateFormat( "yyyyMMddHHmm").format(new Date());
        if (date == null || !date. equals(str)) {
            date = str;
        }
        int random=new Random( ) . nextInt(900)+100;//为变量赋随机值100-999;
        long orderNo = Long.parseLong((date)) * 10000;
        orderNo += random;
        return orderNo+"";
    }

}
